// components/cms-discount/cms-discount.js
//cms优惠券
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    type: { //1默认一行一个，2一行两个
      type: Number,
      value: 1
    },
    item: {
      type: Object,
      value: '',
      observer(newVal, oldVal, changedPath) {
        if (newVal) {
          this.initData(newVal);
        }
      }
    },
  },

  /**
   * 组件的初始数据
   */
  data: {
    isDesShow: false,
    rotateAnimation: {
      data: null,
      animation: null,
      rotate: 0
    },
    desText: ''
  },

  /**
   * 组件的方法列表
   */
  methods: {
    //初始化数据
    initData: function(item) {
      let tmpDesText = "";
      if (item.productRange.type == 0) {
        tmpDesText += "1.适用全部商品（活动商品除外），以下单时为准\n"
      } else {
        tmpDesText += "1.适用部分商品（不含活动商品），以下单时为准\n"
      }
      tmpDesText += "2.该券与全部促销活动不可叠加使用\n"
      if (item.siteRange.type == 0) {
        tmpDesText += "3.全部站点可用，以下单时为准"
      } else {
        tmpDesText += "3.部分站点可用，以下单时为准"
      }

      this.setData({
        desText: tmpDesText
      });
    },
    //动画
    onArrow: function() {
      //动画
      if (!this.data.rotateAnimation.animation) {
        let tempRotateAnimation = this.data.rotateAnimation;
        let animation = wx.createAnimation({
          timingFunction: 'ease',
        });
        tempRotateAnimation.animation = animation;
        this.setData({
          rotateAnimation: tempRotateAnimation
        });
      }
      let tempRotateAnimation = this.data.rotateAnimation;
      let tempRotate = (tempRotateAnimation.rotate == -180) ? 0 : -180;
      tempRotateAnimation.rotate = tempRotate;
      tempRotateAnimation.animation.rotate(tempRotate).step();
      tempRotateAnimation.data = tempRotateAnimation.animation.export();
      this.setData({
        isDesShow: !this.data.isDesShow,
        rotateAnimation: tempRotateAnimation
      });
    },
    //立即领取
    onGet: function() {
      this.triggerEvent('get', null, {});
    },
    //去使用
    onUse: function() {
      this.triggerEvent('use', null, {});
    }
  }
})